package org.afun.csms_android;

import androidx.appcompat.app.AppCompatActivity;

import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Environment;
import android.view.WindowManager;
import android.widget.Toast;
import android.widget.VideoView;

import java.io.File;

public class VideoPlayer extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_player);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        VideoView videoView = (VideoView)findViewById(R.id.videoView);
        File file = new File(Environment.getExternalStorageDirectory()+"/name.mp4");
        if (file.exists()){
            videoView.setVideoPath(file.getAbsolutePath());
        }else{
            Toast.makeText(VideoPlayer.this, "要播放的视频文件不存在", Toast.LENGTH_SHORT).show();
        }

        android.widget.MediaController mc = new android.widget.MediaController(VideoPlayer.this);
        videoView.setMediaController(mc);
        videoView.requestFocus();
        videoView.start();
        videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                Toast.makeText(VideoPlayer.this, "视频播放完毕", Toast.LENGTH_SHORT).show();
            }
        });
    }
}